<?php

namespace Modules\Asset\Entities;

use Modules\Core\Entities\BaseEntity as Model;
use ThrowException;

use DB;

// 福袋资产
class BankCard extends Model
{
    protected $guarded = [];
    protected $table = 'bank_cards';
    static public $resourceName = '';

    // 所属用户
    public function user()
    {
        return $this->belongsTo('\Modules\User\Entities\User', 'user_id');
    }

    public function scopeSearch($query, $key)
    {
        return $query->whereHas('user', function ($q) use ($key) {
            return $q->where('name', 'like', '%' . $key . '%')->orWhere('phone', $key);
        })->orWhere('bank_account_number', 'like', '%' . $key . '%')->orWhere('bank_account_name', 'like', '%' . $key . '%');
    }
}
